package org.freez4.spring.configuration.metadata;

import org.freez4.spring.ioc.overview.domain.User;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Spring XML 元素扩展示例
 *
 * @author 阿坤同学
 * @date 2024/1/14 23:16
 */
public class ExtensibleXmlAuthoringDemo {

    private static final Logger logger = Logger.getLogger(ExtensibleXmlAuthoringDemo.class.getName());

    public static void main(String[] args) {

        // 创建 IoC 底层容器
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        // 创建 XML 资源的 BeanDefinitionReader
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        // 记载 XML 资源
        reader.loadBeanDefinitions("META-INF/users-context.xml");
        // 获取 User Bean 对象
        User user = beanFactory.getBean(User.class);
        logger.log(Level.INFO, () -> "user" + user);
    }
}